<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title></title>
  <link rel="stylesheet" href="/css/main.css"/>
  <link rel="stylesheet" href="/cms/layui/css/layui.css">
  <script src="/js/uikit.js"></script>
</head>

<body>

<div th:insert="~{common::#header}"></div>

<div class="uk-section uk-section-muted">
  <div class="uk-container">
    <div class="uk-background-default uk-border-rounded uk-box-shadow-small">
      <div class="uk-container uk-container-xsmall uk-padding-large">
        <article class="uk-article">
          <h1 class="uk-article-title" style="text-align: center;">我的个人信息</h1>
          <div class="uk-article-content">
            <form class="uk-form-stacked uk-margin-medium-top layui-form" onsubmit="return false;">




              <div class="uk-margin-bottom">
                <div class="row">
                  <div class="sidebar-userpic" style="margin: 0 auto">
                    <img th:src="'/' +${session.current_user.headImg}" style="margin-left: 43%;
    padding: 3px;
    border: 2px solid rgb(210, 214, 222);
    border-radius: 50% 50% 50% 50%;
    width: 140px;
    height: 140px;" class="img-responsive" alt="">
                  </div>
                </div>
              </div>


              <div class="uk-margin-bottom">
                <label class="uk-form-label" for="name">用户名</label>
                <div class="uk-form-controls">
                  <input id="name" class="uk-input uk-border-rounded" th:value="${session.current_user.name}" autocomplete="off" name="name" type="text"
                         required="">
                </div>
              </div>




              <div class="uk-margin-bottom">
                <label class="uk-form-label">邮箱</label>
                <div class="uk-form-controls">
                  <input class="uk-input uk-border-rounded" th:value="${session.current_user.email}"  name="email" disabled="disabled">
                </div>
              </div>

              <div class="uk-margin-bottom">
                <label class="uk-form-label">手机号</label>
                <div class="uk-form-controls">
                  <input class="uk-input uk-border-rounded"  th:value="${session.current_user.phone}"  name="phone">
                </div>
              </div>


              <div class="uk-margin-bottom">
                <label class="uk-form-label">密码</label>
                <div class="uk-form-controls">
                  <input class="uk-input uk-border-rounded" placeholder="不输入则不会进行密码修改！"  name="password">
                </div>
              </div>

              <input type="hidden" th:value="${session.current_user.status}" name="status">
              <input type="hidden" th:value="${session.current_user.role}" name="role">
              <input type="hidden" th:value="${session.current_user.id}" name="id">



              <div class="uk-margin-bottom">
                <label class="uk-form-label">修改头像</label>
                <div class="uk-form-controls">
                  <input type="file" class="uk-input uk-border-rounded" id="imgHeadUpload">
                  <input type="hidden" class="form-control" th:value="${session.current_user.headImg}"
                         id="imgHead" name="headImg">
                </div>
              </div>



              <div class="uk-text-center">
                <input class="uk-button uk-button-primary uk-border-rounded" type="submit" lay-submit=""
                       lay-filter="formSubmit" value="更改个人信息">
              </div>
            </form>
          </div>
        </article>
      </div>
    </div>
  </div>
</div>


<script src="/js/awesomplete.js"></script>
<script src="/js/custom.js"></script>
<script src="/cms/layui/layui.js" charset="utf-8"></script>

<script>
  layui.use(['layedit', 'form'], function () {
    var form = layui.form;
    var $ = layui.$;
    $(document).on('change', '#imgHeadUpload', function () {
      var editImage = $("#imgHeadUpload").get(0).files[0];
      console.log(editImage);
      var formDate = new FormData();
      formDate.append("editImage", editImage);
      $.ajax({
        url: '/file/upload',
        type: 'POST',
        processData: false,
        contentType: false,
        async: false,
        data: formDate,
        success: function (result) {
          if (result.code == 200) {
            $("#imgHead").val("");
            $("#imgHead").val(result.data);
          } else {
            alert("上传失败");
          }
        }
      })
    })


    //监听提交
    form.on('submit(formSubmit)', function (data) {
      $.ajax({
        url: '/cms/user/update',
        type: 'POST',
        dataType: 'JSON',
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(data.field),
        success: function (result) {
          if (result.code == 200) {
            layer.msg(result.msg);
            return false;
          } else {
            layer.msg(result.msg);
            return false;
          }
        }
      })
      return false;

    })
  });
</script>

</body>

</html>